<template>
    <div id="cc">
        <div style="position: sticky;top:0;z-index: 9999;background: #fff;">
            <div style="display: flex;flex-direction: row;height: 40px;">
                <div
                        style="display: flex;justify-content: center;align-items: center;width: 25vw;
                        font-family: PingFangSC-Regular;font-size: 14px;"
                        :style="{borderBottom:activeStep==index?'2px solid #454592':'1px solid #ddd',color:activeStep==index?'#454592':'#333'}"
                        v-for="(item,index) in ['基本','疾病','合病症','治疗']"
                        @click="privilegeHeadClick('anchor-'+index)">
                    <span>
                      {{item}}
                    </span>
                </div>
            </div>
        </div>
        <div class="wrapper">
            <!--基本信息-->
            <div id="anchor-0" class="privilege-wrap">
                <!--标题-->
                <div class="title">
                    <div class="title_block"></div>
                    <div class="title_text">
                        基本信息
                    </div>
                </div>
                <!--field-->
                <div class="field_item">
                    <div class="field_title">
                        年龄
                    </div>
                    <div>
                        <Field v-model="form.tabBasic.B02" type="number"/>
                    </div>
                </div>
                <div class="field_item">
                    <div class="field_title">
                        性别
                    </div>
                    <div>
                        <Cell is-link :title="form.tabBasic.B03" @click="genderShow=true"/>
                    </div>
                </div>
                <div class="field_item">
                    <div class="field_title">
                        地点
                    </div>
                    <div>
                        <Cell is-link :title="form.tabBasic.B01" @click="locationShow=true"/>
                    </div>
                </div>
            </div>
            <Overlay :show="genderShow">
                <RadioList :fullList="genderOptions" :checked="form.tabBasic.B03" @confirm="genderConfirm"
                           @cancel="genderShow=false"/>
            </Overlay>
            <Overlay :show="locationShow">
                <RadioList :fullList="locationOptions" :checked="form.tabBasic.B01" @confirm="locationConfirm"
                           @cancel="locationShow=false"/>
            </Overlay>
            <!--基本信息-->
            <!--疾病信息-->
            <div class="mt20 privilege-wrap" id="anchor-1">
                <!--标题-->
                <div class="title">
                    <div class="title_block"></div>
                    <div class="title_text">
                        疾病信息
                    </div>
                </div>
                <!--field-->

                <div class="field_item">
                    <div class="field_title">
                        是否首次发作卒中
                    </div>
                    <div>
                        <Cell is-link :title="form.tabDisease.D24" @click="firstStrokShow=true"/>
                    </div>
                </div>
            </div>
            <Overlay :show="firstStrokShow">
                <RadioList :fullList="firstStrokeOptions" :checked="form.tabDisease.D24" @confirm="firstStrokConfirm"
                           @cancel="firstStrokShow=false"/>
            </Overlay>

            <!--疾病信息-->
            <!--合并症信息-->
            <div class="mt20 privilege-wrap" id="anchor-2">
                <!--标题-->
                <div class="title">
                    <div class="title_block"></div>
                    <div class="title_text">
                        合并症信息
                    </div>
                </div>
                <!--field-->

                <div class="field_item">
                    <div class="field_title">
                        伴发疾病及既往史(多选)
                    </div>
                    <div>
                        <Cell is-link :title="form.tabComplication.C15.join(',')" @click="diseaseHistoryShow=true"/>
                    </div>
                </div>
                <div v-if="form.tabComplication.C15.includes('高血压')">
                    <div class="title_sub">
                        高血压
                    </div>
                    <div class="field_item">
                        <div class="field_title">
                            舒张压(mmHg)
                        </div>
                        <div>
                            <Field v-model="form.tabComplication.C14" type="number"/>
                        </div>
                    </div>
                    <div class="field_item">
                        <div class="field_title">
                            收缩压(mmHg)
                        </div>
                        <div>
                            <Field v-model="form.tabComplication.C13" type="number"/>
                        </div>
                    </div>
                </div>
                <div v-if="form.tabComplication.C15.includes('糖尿病')">
                    <div class="title_sub">
                        糖尿病
                    </div>
                    <div class="field_item">
                        <div class="field_title">
                            当前治疗方案
                        </div>
                        <div>
                            <Cell is-link :title="form.tabComplication.C01"
                                  @click="currentTherapeuticShow=true"/>
                        </div>
                    </div>
                    <div class="field_item">
                        <div class="field_title">
                            仅二甲双胍控制
                        </div>
                        <div>
                            <Cell is-link :title="form.tabComplication.C02"
                                  @click="metformincontrolShow=true"/>
                        </div>
                    </div>
                    <div class="field_item">
                        <div class="field_title">
                            空腹血糖(mmol/L)
                        </div>
                        <div>
                            <Field v-model="form.tabComplication.D01" type="number"/>
                        </div>
                    </div>
                    <div class="field_item">
                        <div class="field_title">
                            餐后血糖(mmol/L)
                        </div>
                        <div>
                            <Field v-model="form.tabComplication.D02" type="number"/>
                        </div>
                    </div>
                    <div class="field_item">
                        <div class="field_title">
                            糖化血红蛋白(%)
                        </div>
                        <div>
                            <Field v-model="form.tabComplication.D03" type="number"/>
                        </div>
                    </div>
                </div>
            </div>
            <Overlay :show="diseaseHistoryShow">
                <CheckboxList :fullList="diseaseHistoryOptions" :checked="form.tabComplication.C15"
                              @confirm="diseaseHistoryconfirm" @cancel="diseaseHistoryShow = false"/>
            </Overlay>
            <Overlay :show="currentTherapeuticShow">
                <RadioList :fullList="currentTherapeuticOption" :checked="form.tabComplication.C01" @confirm="currentTherapeuticConfirm"
                           @cancel="currentTherapeuticShow=false"/>
            </Overlay>
            <Overlay :show="metformincontrolShow">
                <RadioList :fullList="metformincontrolOptions" :checked="form.tabComplication.C02" @confirm="metformincontrolConfirm"
                           @cancel="metformincontrolShow=false"/>
            </Overlay>


            <!--合并症信息-->
            <!--治疗信息-->
            <div class="mt20 privilege-wrap" id="anchor-3">
                <!--标题-->
                <div class="title">
                    <div class="title_block"></div>
                    <div class="title_text">
                        治疗信息
                    </div>
                </div>
                <!--field-->

                <div class="field_item">
                    <div class="field_title">
                        既往抗血小板治疗方案（可多选）
                    </div>
                    <div>
                        <Cell is-link :title="form.treatment.T09.join(',')" @click="antiplateletHistoryShow=true"/>
                    </div>
                </div>
                <div class="field_item">
                    <div class="field_title">
                        当前抗血小板治疗方案（可多选）
                    </div>
                    <div>
                        <Cell is-link :title="form.treatment.T05.join(',')"
                              @click="currentantiplateletHistoryShow=true"/>
                    </div>
                </div>
                <div class="field_item">
                    <div class="field_title">
                        建议波立维用药时间（月）
                    </div>
                    <div>
                        <Cell is-link :title="form.treatment.T08.join(',')"
                              @click="aprovelrecommandShow=true"/>
                    </div>
                </div>
            </div>
            <Overlay :show="antiplateletHistoryShow">
                <CheckboxList :fullList="antiplateletOptions" :checked="form.treatment.T09"
                              @confirm="antiplateletHistoryconfirm" @cancel="antiplateletHistoryShow = false"/>
            </Overlay>
            <Overlay :show="currentantiplateletHistoryShow">
                <CheckboxList :fullList="currentantiplateletOptions" :checked="form.treatment.T05"
                              @confirm="currentantiplateletconfirm" @cancel="currentantiplateletHistoryShow = false"/>
            </Overlay>
            <Overlay :show="aprovelrecommandShow">
                <CheckboxList :fullList="aprovelrecommandOptions" :checked="form.treatment.T08"
                              @confirm="aprovelrecommandconfirm" @cancel="aprovelrecommandShow = false"/>
            </Overlay>

            <!--治疗信息-->
            <!--保存按钮-->
            <div class="submit">
                <div class="submit_btn" @click="save">
                    保存
                </div>
            </div>
            <div class="submit_btn2" @click="submit">
                提交
            </div>
        </div>
        <div>
            <img :src="cloud_img" style="width: 100%"/>
        </div>
    </div>

</template>

<script>
    import {
        Field,
        Cell,
        CellGroup,
        Popup,
        Picker,
        Toast,
        Overlay,
        Checkbox,
        CheckboxGroup
    } from 'vant';
    import cloud_img from '@assets/image/cloud.svg'
    import RadioList from "@components/snfRadioList/index";
    import CheckboxList from "@components/snfCheckboxList/index";
    const genderOptions = ['男', '女']
    const locationOptions = ['病房', '门诊']
    const firstStrokeOptions = ['是', '否']
    const diseaseHistoryOptions = ['糖尿病', '高血压', '胃肠道出血史', '痛风史', '哮喘', '多血管床病变', '其它', '无']
    const currentTherapeuticOption = ['新诊断/未治疗', '仅OAD', '基础+OAD', '基础追加', '基础餐时', '短期强化', '其他']
    const metformincontrolOptions = ['是', '否']
    const antiplateletOptions = ['氯吡格雷', '阿司匹林', '其他', '无']
    const currentantiplateletOptions = ['波立维®', '阿司匹林', '其他']
    const aprovelrecommandOptions = ['<3', '3-12(不包括12)', '≥12']
    export default {
        name: "add",
        props: {
            scheduleId: String,
            tabActive: Number
        },
        components: {
            RadioList,
            CheckboxList,
            Field,
            Cell,
            Popup,
            Picker,
            Toast,
            Overlay,
            Checkbox,
            CheckboxGroup,
            CellGroup
        },
        data() {
            return {
                active: '',
                activeStep: '',
                form: {
                    callPlanId: this.scheduleId,
                    prodName: '波立维 卒中',
                    prodId: 'PLAVIX_STROKE',
                    tabBasic: {
                        B02: '',
                        B03: '',
                        B01: ''
                    },
                    tabDisease: {
                        D24: ''
                    },
                    tabComplication: {
                        C15: [],
                        C14: '',
                        C13: '',
                        C01: '',
                        C02: '',
                        D01: '',
                        D02: '',
                        D03: ''
                    },
                    treatment: {
                        T09: [],
                        T05: [],
                        T08: []
                    }
                },
                genderShow: false,
                locationShow: false,
                firstStrokShow: false,
                diseaseHistoryShow: false,
                currentTherapeuticShow: false,
                metformincontrolShow: false,
                antiplateletHistoryShow: false,
                currentantiplateletHistoryShow: false,
                aprovelrecommandShow: false,
                genderOptions: genderOptions,
                locationOptions: locationOptions,
                firstStrokeOptions: firstStrokeOptions,
                diseaseHistoryOptions: diseaseHistoryOptions,
                currentTherapeuticOption: currentTherapeuticOption,
                metformincontrolOptions: metformincontrolOptions,
                antiplateletOptions: antiplateletOptions,
                currentantiplateletOptions: currentantiplateletOptions,
                aprovelrecommandOptions: aprovelrecommandOptions,
                cloud_img:cloud_img
            }
        },
        methods: {

            aprovelrecommandconfirm(value, index) {
                this.form.treatment.T08 = value
                this.aprovelrecommandShow = false
            },
            currentantiplateletconfirm(value, index) {
                this.form.treatment.T05 = value
                this.currentantiplateletHistoryShow = false
            },
            antiplateletHistoryconfirm(value, index) {
                this.form.treatment.T09 = value
                this.antiplateletHistoryShow = false
            },
            diseaseHistoryconfirm(value, index) {
                this.form.tabComplication.C15 = value
                this.diseaseHistoryShow = false
            },
            onScroll(e) {
                let scrollItems = document.querySelectorAll(".privilege-wrap");
                for (let i = scrollItems.length - 1; i >= 0; i--) {
                    // 判断滚动条滚动距离是否大于当前滚动项可滚动距离
                    let judge =
                        e.target.scrollTop >=
                        scrollItems[i].offsetTop - scrollItems[0].offsetTop;
                    if (judge) {
                        this.activeStep = i;
                        this.active = this.activeStep
                        break;
                    }
                }
            },
            privilegeHeadClick(anchor) {
                this.$nextTick(() => {
                    document.querySelector(`#${anchor}`).scrollIntoView({
                        behavior: "smooth", // 平滑过渡
                        block: "start" // 上边框与视窗顶部平齐。默认值
                    });
                });
            },
            aprovelrecommandShowtoggle(index) {
                this.$refs.aprovelrecommandcheckboxes[index].toggle();
            },
            currentantiplateletOptionstoggle(index) {
                this.$refs.currentantiplateletcheckboxes[index].toggle();
            },
            antiplatelettoggle(index) {
                this.$refs.antiplateletcheckboxes[index].toggle();
            },
            toggle(index) {
                this.$refs.checkboxes[index].toggle();
            },
            genderConfirm(value, index) {
                this.form.tabBasic.B03 = value
                this.genderShow = false
            },
            locationConfirm(value, index) {
                this.form.tabBasic.B01 = value
                this.locationShow = false
            },
            firstStrokConfirm(value, index) {
                this.form.tabDisease.D24 = value
                this.firstStrokShow = false
            },
            currentTherapeuticConfirm(value, index) {
                this.form.tabComplication.C01 = value
                this.currentTherapeuticShow = false
            },
            metformincontrolConfirm(value, index) {
                this.form.tabComplication.C02 = value
                this.metformincontrolShow = false
            },
            saveCheck() {

                if (!this.form.tabBasic.B02) {
                    alert("请输入年龄！")
                    return false
                }

                if (!this.form.tabBasic.B03) {
                    alert("请输入性别！")
                    return false
                }

                if (!this.form.tabBasic.B01) {
                    alert("请输入地点！")
                    return false
                }
                if (!this.form.tabDisease.D24) {
                    alert("请选择是否首次发作卒中！")
                    return false
                }
                if (this.form.tabComplication.C15.length < 1) {
                    alert("请选择伴发疾病及既往史！")
                    return false
                }
                if (this.form.tabComplication.C15.includes('糖尿病')) {
                    if (!this.form.tabComplication.C01) {
                        alert("请选择当前治疗方案！")
                        return false
                    }
                    if (!this.form.tabComplication.C02) {
                        alert("请选择仅二甲双胍控制！")
                        return false
                    }
                    if (!this.form.tabComplication.D01) {
                        alert("请输入空腹血糖！")
                        return false
                    }
                    if (!this.form.tabComplication.D02) {
                        alert("请输入餐后血糖！")
                        return false
                    }
                    if (!this.form.tabComplication.D03) {
                        alert("请输入糖化血红蛋白！")
                        return false
                    }
                }

                if (this.form.tabComplication.C15.includes('高血压')) {
                    if (!this.form.tabComplication.C14) {
                        alert("请输入舒张压！")
                        return false
                    }
                    if (!this.form.tabComplication.C13) {
                        alert("请输入收缩压！")
                        return false
                    }
                }

                if (this.form.treatment.T09.length < 1) {
                    alert("请选择既往抗血小板治疗方案")
                    return false
                }
                if (this.form.treatment.T05.length < 1) {
                    alert("请选择当前抗血小板治疗方案！")
                    return false
                }
                if (this.form.treatment.T08.length < 1) {
                    alert("请选择建议波立维用药时间！")
                    return false
                }
                return true
            },
            save() {
                this.form.finish = false
                if(this.form.finish){
                    this.$emit('save', Object.assign({}, this.form))
                    this.$emit('hide')
                }else{
                    return
                }
                this.$nextTick(() => {
                    document.querySelector(`#cc`).scrollIntoView({
                        block: "start" // 上边框与视窗顶部平齐。默认值
                    });
                });
                this.form = {
                    finish:false,
                    callPlanId: this.scheduleId,
                    prodName: '波立维 卒中',
                    prodId: 'PLAVIX_STROKE',
                    tabBasic: {
                        B02: '',
                        B03: '',
                        B01: ''
                    },
                    tabDisease: {
                        D24: ''
                    },
                    tabComplication: {
                        C15: [],
                        C14: '',
                        C13: '',
                        C01: '',
                        C02: '',
                        D01: '',
                        D02: '',
                        D03: ''
                    },
                    treatment: {
                        T09: [],
                        T05: [],
                        T08: []
                    }
                }
            },
            submit(){
                this.form.finish = this.saveCheck()
                this.$emit('save', Object.assign({}, this.form))
                this.$nextTick(() => {
                    document.querySelector(`#cc`).scrollIntoView({
                        block: "start" // 上边框与视窗顶部平齐。默认值
                    });
                });
                this.form = {
                    finish:false,
                    callPlanId: this.scheduleId,
                    prodName: '波立维 卒中',
                    prodId: 'PLAVIX_STROKE',
                    tabBasic: {
                        B02: '',
                        B03: '',
                        B01: ''
                    },
                    tabDisease: {
                        D24: ''
                    },
                    tabComplication: {
                        C15: [],
                        C14: '',
                        C13: '',
                        C01: '',
                        C02: '',
                        D01: '',
                        D02: '',
                        D03: ''
                    },
                    treatment: {
                        T09: [],
                        T05: [],
                        T08: []
                    }
                }
                this.$emit('hide')
            }
        },
        mounted() {
        },
        watch: {
            tabActive(newval, oldval) {
                this.activeStep = newval
            },
            'form.tabComplication.C15': {
                handler(newval, oldval) {
                    if (!newval.includes('糖尿病')) {
                        this.form.tabComplication.C01 = ''
                        this.form.tabComplication.C02 = ''
                        this.form.tabComplication.D01 = ''
                        this.form.tabComplication.D02 = ''
                        this.form.tabComplication.D03 = ''
                    }
                    if (!newval.includes('高血压')) {
                        this.form.tabComplication.C14 = ''
                        this.form.tabComplication.C13 = ''
                    }
                }
            }
        }
    }
</script>

<style scoped>
    .wrapper {
        padding: 20px;
    }

    .title {
        display: flex;
        flex-direction: row;
        align-items: center;
        /*margin-bottom: 10px;*/
    }

    .title_block {
        background: #ACB318;
        width: 4px;
        height: 20px;
    }

    .title_text {
        font-family: PingFangSC-Semibold;
        font-size: 16px;
        color: #333333;
        letter-spacing: 0.3px;
        text-align: justify;
        line-height: 24px;
        margin-left: 12px;
    }

    .field_title {
        font-family: PingFangSC-Regular;
        font-size: 12px;
        color: #999999;
        letter-spacing: 0.22px;
        text-align: justify;
        line-height: 16px;
    }

    .field_item {
        margin-top: 10px;
    }

    .title_sub {
        font-family: PingFangSC-Regular;
        font-size: 14px;
        color: #454592;
        letter-spacing: 0.26px;
        text-align: justify;
        margin-top: 20px;
    }

    .submit {
        width: 100%;
        height: 48px;
        display: flex;
        justify-content: center;
        margin-top: 50px;
        margin-bottom: 20px;
    }

    .submit_btn {
        width: 90%;
        height: 48px;
        background: #ACB318;
        border-radius: 2px;
        border-radius: 2px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #fff;
    }
    .submit_btn2{
        width: 90%;
        height: 48px;
        background: #454592;
        border-radius: 2px;
        border-radius: 2px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #fff;
        margin: 0 auto;
    }

    .mt20 {
        margin-top: 20px;
    }

    .van-cell {
        padding: 10px 0px !important;
        border-bottom: 1px solid #ddd;
    }
</style>